package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 物资去处
 * @Author: Mr.Cao
 * @DateTime: 2021/11/10 14:36
 * BMW F750GS
 **/
@RestController
@RequestMapping("business/consumer/")
public class ConsumerController {

    @Autowired
    private ConsumerService consumerService;

    /**
     * 分页带条件查询 物资去向
     * */
    //http://www.localhost:8989/business/consumer/findConsumerList?pageNum=1&pageSize=10&name=
    @GetMapping("findConsumerList")
    public ResponseBean findInStockList(@RequestParam Map queryMap){
        PageVO pageVO =  consumerService.findInStockList(queryMap);
        return ResponseBean.success(pageVO);
    }
    /**
     * 编辑时做数据的回显
     * */
    //http://www.localhost:8989/business/consumer/edit/8
    @GetMapping("edit/{id}")
    public ResponseBean edit(@PathVariable long id){
        ConsumerVO  consumerVO =  consumerService.edit(id);
        return ResponseBean.success(consumerVO);
    }
    /**
     * 编辑物资去向
     * */
    //http://www.localhost:8989/business/consumer/update/8
    @PutMapping("update/{id}")
    public ResponseBean update(@PathVariable long id ,@RequestBody ConsumerVO consumerVO){
        consumerService.update(id,consumerVO);
        return ResponseBean.success();
    }
    /**
     * 删除物资发放去向
     * */
    //http://www.localhost:8989/business/consumer/delete/8
    @DeleteMapping("delete/{id}")
    public ResponseBean delete(@PathVariable long id ){
        consumerService.delete(id);
        return ResponseBean.success();
    }
    /**
     * 添加物资发放去向
     * */
    //http://www.localhost:8989/consumer/add
    @PostMapping("add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    /**
     * 查询全部去向
     * */
    //http://www.localhost:8989/business/consumer/findAll
    @GetMapping("findAll")
    public ResponseBean findAll(){
     List list =   consumerService.findAll();
        return ResponseBean.success(list);
    }
}
